package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.VideosService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Map;

@RestController
@RequestMapping("/smallVideos")
public class SmallVideosController {
    @Autowired
    private VideosService videosService;

    /**
     * 视频发布
     *
     * @param videoThumbnail 视频封面文件
     * @param videoFile      视频
     * @return
     */
    @PostMapping
    public ResponseEntity smallVideos(MultipartFile videoThumbnail, MultipartFile videoFile) throws IOException {
        videosService.smallVideos(videoThumbnail, videoFile);
        return ResponseEntity.ok(null);
    }


    /**
     * 查看视频列表
     *
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping
    public ResponseEntity findAllSmallVideos(@RequestParam(defaultValue = "1") Integer page,
                                             @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult pr = videosService.findAllSmallVideos(page, pagesize);
        return ResponseEntity.ok(pr);
    }

    /**
     * 视频用户关注
     * @param id
     * @return
     */
    @PostMapping("/{uid}/userFocus")
    public ResponseEntity userFocus(@PathVariable("uid") Long id) {
        videosService.userFocus(id);
        return ResponseEntity.ok(null);
    }

    /**
     * 取消视频用户关注
     * @param id
     * @return
     */
    @PostMapping("/{uid}/userUnFocus")
    public ResponseEntity userUnFocus(@PathVariable("uid") Long id) {
        videosService.userUnFocus(id);
        return ResponseEntity.ok(null);
    }
}
